package com.anolesoft.yr.mbus.prod.model.mapper;

import com.anolesoft.yr.mbus.prod.model.dto.ProdProductionDeleteDTO;
import com.anolesoft.yr.mbus.prod.model.dto.ProdProductionSaveDTO;
import com.anolesoft.yr.mbus.prod.model.dto.ProdProductionUpdateDTO;
import com.anolesoft.yr.mbus.prod.model.entity.ProdProduction;
import com.anolesoft.yr.mbus.prod.model.sql.ProdProductionSQL;
import com.anolesoft.yr.mbus.prod.model.vo.ProdProductionQueryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ProdProductionMapper {

    //新增时查询产品编号是否已经存在
    @Select(ProdProductionSQL.QUERY_PROD_PRODUCTION_BY_CODE)
    @Results(id = "queryProdProductionByCode", value = {
            @Result(column = "count", property = "count")
    })
    int queryProdProductionByCode(String prodCode);

    //新增时查询产品名称是否已经存在
    @Select(ProdProductionSQL.QUERY_PROD_PRODUCTION_BY_NAME)
    @Results(id = "queryProdProductionByName", value = {
            @Result(column = "count", property = "count")
    })
    int queryProdProductionByName(String prodName);

    //新增产品信息表
    @Insert(ProdProductionSQL.SAVE_PROD_PRODUCTION)
    int saveProdProduction(ProdProductionSaveDTO prodProductionSaveDTO);

    //根据主键查询产品唯一数据
    @Select(ProdProductionSQL.QUERY_PROD_PRODUCTION_BY_UID2)
    @Results(id = "queryProdProductionByUid2", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "fac_code", property = "facCode"),
            @Result(column = "prod_type_uid", property = "prodTypeUid"),
            @Result(column = "prod_code", property = "prodCode"),
            @Result(column = "prod_name", property = "prodName"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime"),
            @Result(column = "m_user_uid", property = "mmUserUid"),
            @Result(column = "m_time", property = "mmTime"),
            @Result(column = "del_flag", property = "delFlag")
    })
    ProdProduction queryProdProductionByUid2(String uid);

    //修改时查询产品编号是否已经存在（不包含本身）
    @Select(ProdProductionSQL.QUERY2_PROD_PRODUCTION_BY_CODE)
    @Results(id = "query2ProdProductionByCode", value = {
            @Result(column = "count", property = "count")
    })
    int query2ProdProductionByCode(@Param("prodTypeUid") String prodTypeUid, @Param("prodCode") String prodCode, @Param("prodCode2") String prodCode2);

    //修改时查询产品名称是否已经存在（不包含本身）
    @Select(ProdProductionSQL.QUERY2_PROD_PRODUCTION_BY_NAME)
    @Results(id = "query2ProdProductionByName", value = {
            @Result(column = "count", property = "count")
    })
    int query2ProdProductionByName(@Param("prodTypeUid") String prodTypeUid, @Param("prodName") String prodName, @Param("prodName2") String prodName2);

    //修改产品信息表
    @Update(ProdProductionSQL.UPDATE_PROD_PRODUCTION)
    int updateProdProduction(ProdProductionUpdateDTO prodProductionUpdateDTO);

    //删除产品信息
    @Update(ProdProductionSQL.DELETE_PROD_PRODUCTION)
    int deleteProdProduction(String objuid);

    //根据主键查询产品唯一数据
    @Select(ProdProductionSQL.QUERY_PROD_PRODUCTION_BY_UID)
    @Results(id = "qrodProductionByUid", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "prod_type_uid", property = "prodTypeUid"),
            @Result(column = "type_name", property = "typeName"),
            @Result(column = "prod_code", property = "prodCode"),
            @Result(column = "prod_name", property = "prodName"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime")
    })
    ProdProductionQueryVO qrodProductionByUid(String uid);

    //根据条件查询产品数据条数
    @Select(ProdProductionSQL.QUERY_PROD_PRODUCTION_ALL_COUNT)
    @Results(id = "queryProdProductionAllCount", value = {
            @Result(column = "count", property = "count")
    })
    int queryProdProductionAllCount(@Param("typeName") String typeName, @Param("prodName") String prodName);

    //根据条件查询产品所有数据
    @Select(ProdProductionSQL.QUERY_PROD_PRODUCTION_ALL)
    @Results(id = "queryProdProductionAll", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "type_name", property = "typeName"),
            @Result(column = "prod_code", property = "prodCode"),
            @Result(column = "prod_name", property = "prodName"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "c_user_uid", property = "ccUserUid"),
            @Result(column = "c_time", property = "ccTime")
    })
    List<ProdProductionQueryVO> queryProdProductionAll(@Param("typeName") String typeName, @Param("prodName") String prodName, @Param("page") int page, @Param("limit") int limit);

    //查询产品名称
    @Select(ProdProductionSQL.QUERY_PROD_PRODUCTION_PROD_NAME)
    @Results(id = "queryProdProductionProdName", value = {
            @Result(column = "objuid", property = "objuid"),
            @Result(column = "prod_name", property = "prodName")
    })
    List<ProdProductionQueryVO> queryProdProductionProdName();

}
